cd ${work}5_reg_analysis

local ylist		"exp_status log_vrd_exp_exsmall"
local felist	`" "IDY FD" "IDY FD FY" "'
local wlist		`" "c.sales##c.sales##c.sales##c.sales" "" "'

use temp\regsample_idt, clear

gen x_ols	= treated_2
gen int_ols = treated_2 * log(sales)
gen x_fs	= tdcinitiative_2
gen int_fs	= tdcinitiative_2 * log(sales)
gen x_iv	= treated_2
gen int_iv	= treated_2 * log(sales)

lab var x_ols	"$ \overline{support}_{fdt} $"
lab var int_ols	"$ \overline{support}_{fdt} \times $ ln(lagged total sales)"
lab var x_fs	"$ \overline{call}_{fdt} $"
lab var int_fs	"$ \overline{call}_{fdt} \times $ ln(lagged total sales)"
lab var x_iv	"$ \overline{support}_{fdt} $"
lab var int_iv	"$ \overline{support}_{fdt} \times $ ln(lagged total sales)"

eststo clear
local mtitles
local n=1
foreach y of local ylist {
local nfe=1	
foreach fe of local felist {
	
	local w : word `nfe' of `wlist'
	
	eststo est1: reghdfe `y' x_ols int_ols `w', a(`fe') vce(cl F) nosamp
	
	eststo est2: reghdfe x_ols x_fs int_fs `w' if `y'!=. , a(`fe') vce(cl F) nosamp
	
	eststo est3: ivreghdfe `y' ( x_iv int_iv = x_fs int_fs ) `w', a(`fe') cl(F)
	local N = e(N)
	local F = e(widstat)
	
	eststo stacked_`n' : appendmodels est1 est2 est3
	eststo drop est*
	qui estadd scalar N `N'
	qui estadd scalar F `F'
	qui estadd local FE `fe'
	if "`w'"!=""	qui estadd local SC "Yes"
	if "`w'"==""	qui estadd local SC "No"
	local mtitles `mtitles' "`:var lab `y''"
		
	local ++n
	local ++nfe
	
}	
}
	
esttab using output\table_a12.tex, replace booktabs se label ///
	title("Effect of Export Promotion on Trade, Heterogeneity across Firm Size") star(* 0.1 ** 0.05 *** 0.01) mtitles(`mtitles') keep(x_* int_*) ///
	stats(N F FE SC , labels("Observations" "IV F-stat" "Fixed Effects" "Size Control") fmt(%10.0fc %10.0fc "" "")) ///
	refcat(x_ols "OLS" x_fs "First stage" x_iv "2SLS", nolabel)